import axios from 'axios'
import { Message } from 'element-ui'

const service = axios.create({
  timeout: 5000,
})

service.interceptors.request.use(
  (config) => {
    return config
  },
  (error) => {
    console.log(error)
    return Promise.reject()
  }
)

service.interceptors.response.use(
  (response) => {
    if (response.status === 200) {
      if (response.data._RejCode === '00000000') {
      } else {
        Message.error({
          message: response.data._RejMsg,
          duration: 8000,
        })
      }
      return response.data
    } else {
      Promise.reject()
    }
  },
  (error) => {
    console.log(error)
    return Promise.reject()
  }
)

export default service
